package com.car.controller;

import com.car.entity.Emp;
import com.car.service.IEmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

/**
 * @Description:
 * @author: hsy
 * @version: v1.0
 * @Date
 */
@Controller
public class EmpController {
    @Autowired
    @Qualifier("empService")
    private IEmpService iEmpService;

    //查找所有员工
    @GetMapping (value = "/findEmpAll")
    public String findEmpAll(Model model){
        List<Emp> emps = iEmpService.findAll();
        model.addAttribute("emps",emps);
        return "/staff_List.jsp";
    }
    //根据id查找
    @GetMapping(value = "/findEmpById")
    public String findEmpById(int eid, Model model, HttpSession session){
        System.out.println(123);
        Emp emp = iEmpService.findById(eid);
        session.setAttribute("emp",emp);
        model.addAttribute("emp",emp);
        return "/update_Staff.jsp";
    }
    //修改员工信息
    @GetMapping(value = "/updateEmp")
    public String updateEmp(Emp emp){
        System.out.println(456);
        iEmpService.updateEmp(emp);
        return "redirect:/findEmpAll";
    }
    //增加员工
    @GetMapping(value = "/addEmp")
    public String addEmp(Emp emp){
        String ename = emp.getEname();
        System.out.println(ename);
        emp.setStar_regtime(new Date());
        iEmpService.addEmp(emp);
        return "redirect:/findEmpAll";
    }
    //查找员工状态
    @GetMapping(value = "/findStatus")
    public String findStatus(String status,Model model){
        System.out.println(status);
        List<Emp> status1 = iEmpService.findStatus(status);
        System.out.println(status1);
        model.addAttribute("emps",status1);
        return "/staff_List.jsp";
    }
    @GetMapping (value = "/findEmpAll1")
    public String findEmpAll1(Model model){
        List<Emp> emps = iEmpService.findAll();
        model.addAttribute("emps",emps);
        return "/presell_Card.jsp";
    }
}
